"""
进度 | 数据层
"""

from models import TPO
from models.po import (
    RegionAreaPO,
    RegionCityPO,
    RegionProvincePO,
    RegionStreetPO,
)
from service.base import ServiceBase


def get_one_by_code(cls, code: str) -> TPO | None:
    if not code:
        return None

    return cls.find_one({"code": code})


class RegionProvinceService(ServiceBase[RegionProvincePO]):
    """ 行政区划 | 省 | 数据层 """

    po = RegionProvincePO
    collection_name = "common_region_province"
    single_field_index = [
        "code",
        "name",
    ]

    get_one_by_code = classmethod(get_one_by_code)


class RegionCityService(ServiceBase[RegionCityPO]):
    """ 行政区划 | 市 | 数据层 """

    po = RegionCityPO
    collection_name = "common_region_city"
    single_field_index = [
        "code",
        "name",
        "province_code",
    ]

    get_one_by_code = classmethod(get_one_by_code)


class RegionAreaService(ServiceBase[RegionAreaPO]):
    """ 行政区划 | 区 | 数据层 """

    po = RegionAreaPO
    collection_name = "common_region_area"
    single_field_index = [
        "code",
        "name",
        "city_code",
    ]

    get_one_by_code = classmethod(get_one_by_code)


class RegionStreetService(ServiceBase[RegionStreetPO]):
    """ 行政区划 | 街道 | 数据层 """

    po = RegionStreetPO
    collection_name = "common_region_street"
    single_field_index = [
        "code",
        "name",
        "area_code",
    ]

    get_one_by_code = classmethod(get_one_by_code)
